#include "StdAfx.h"
#include "FindResult.h"

FindResult::FindResult(void)
{
	m_pObj = NULL;
	m_objNum = 0;
}


FindResult::~FindResult(void)
{
	if(m_pObj!=NULL)
	{
		for(unsigned int i =0;i<m_objNum;i++)
		{
			m_pObj[i] = NULL;
		}
		delete []m_pObj;
		m_pObj = NULL;
		m_objNum = 0;
	}

}

void FindResult::Release()
{
	if(m_pObj!=NULL)
	{
		for(unsigned int i =0;i<m_objNum;i++)
		{
			m_pObj[i] = NULL;
		}
		delete m_pObj;
		m_pObj = NULL;
		m_objNum = 0;
	}
}
void FindResult::SetDate(IDiskObj**& pObj)
{
	if(m_objNum==0)
	{
		while(pObj[m_objNum]!=NULL)
		{
			m_objNum++;
		}
		m_pObj = new IDiskObj*[m_objNum];
		for(unsigned int i =0;i<m_objNum;i++)
		{
			m_pObj[i] = pObj[i];
		
		}
		
	}
}
void FindResult::SetDate(MyFile**& pObj)
{
	if(m_objNum==0)
	{
		while(pObj[m_objNum]!=NULL)
		{
			m_objNum++;
		}
		m_pObj = new IDiskObj*[m_objNum];
		for(unsigned int i =0;i<m_objNum;i++)
		{
			m_pObj[i] = pObj[i];
			
		}
	}
	else
	{
		unsigned int num =0;
		while(pObj[num]!=NULL)
		{
			num++;
		}
		IDiskObj** pDiskObj = new IDiskObj*[m_objNum+num];
		for(unsigned int i = 0;i<num;i++)
		{
			pDiskObj[i] = pObj[i];
		}
		for(unsigned int i=num,j=0;i<m_objNum+num;i++,j++)
		{
			pDiskObj[i] = m_pObj[j];
			m_pObj[j] = NULL;
		}
		delete []m_pObj;
		m_pObj = pDiskObj;
		pDiskObj = NULL;
		m_objNum = m_objNum + num;
	}
}
void FindResult::SetDate(Dir**& pObj)
{
	if(m_objNum==0)
	{
		while(pObj[m_objNum]!=NULL)
		{
			m_objNum++;
		}
		m_pObj = new IDiskObj*[m_objNum];
		for(unsigned int i =0;i<m_objNum;i++)
		{
			m_pObj[i] = pObj[i];
			
		}
	}
	else
	{
		unsigned int num =0;
		while(pObj[num]!=NULL)
		{
			num++;
		}
		IDiskObj** pDiskObj = new IDiskObj*[m_objNum+num];
		for(unsigned int i = 0;i<num;i++)
		{
			pDiskObj[i] = pObj[i];
		}
		for(unsigned int i=num,j=0;i<m_objNum+num;i++,j++)
		{
			pDiskObj[i] = m_pObj[j];
			m_pObj[j] = NULL;
		}
		delete []m_pObj;
		m_pObj = pDiskObj;
		pDiskObj = NULL;
		m_objNum = m_objNum + num;
	}
}
void FindResult::SetDate(IFindResult* pfr)
{
	if(m_objNum==0)
	{
		m_objNum = pfr->GetCount();
		m_pObj = new IDiskObj*[m_objNum];
		for(unsigned int i = 0;i<m_objNum;i++)
		{
			m_pObj[i] = pfr->GetItemByIdx(i);
		}
	}
	else
	{
		unsigned int num = pfr->GetCount();
		IDiskObj** pObj = new IDiskObj*[m_objNum+num];
		for(unsigned int i = 0;i<num;i++)
		{
			pObj[i] = pfr->GetItemByIdx(i);
		}
		for(unsigned int i=num,j=0;i<m_objNum+num;i++,j++)
		{
			pObj[i] = m_pObj[j];
			m_pObj[j] = NULL;
		}
		delete []m_pObj;
		m_pObj = pObj;
		pObj = NULL;
		m_objNum = m_objNum + num;


	}
}
unsigned int FindResult::GetCount()
{
	return m_objNum;
}
IDiskObj* FindResult::GetItemByIdx(unsigned int id)
{
	return m_pObj[id];
}
